#include "main/utils.h"
using namespace std;

bool isNumber(const string& str) {
  for (auto ele : str) {
    if (ele >= '0' && ele <= '9') {
      continue;
    } else {
      return false;
    }
  }
  return true;
}

int calculate(const int& num1, const int& num2, string op) {
  int ret = -1;
  if (op == "+") {
    ret = num1 + num2;
  } else if (op == "-") {
    ret = num1 - num2;
  } else if (op == "*") {
    ret = num1 * num2;
  } else if (op == "/") {
    ret = num1 / num2;
  }
  return ret;
}

int evalRPN(const vector<string>& input) {
  stack<int> help_stack;
  int result = 0;
  for (int i = 0; i < input.size(); ++i) {
    if (isNumber(input[i])) {
      help_stack.push(stoi(input[i]));
    } else if (input[i] == "+" ||
               input[i] == "-" ||
               input[i] == "*" ||
               input[i] == "/") {
      int num1 = help_stack.top();
      help_stack.pop();
      int num2 = help_stack.top();
      help_stack.pop();
      result = calculate(num1, num2, input[i]);
      help_stack.push(result);
    }
  }
  return help_stack.top();
}

int main() {
  vector<string> input = {"20", "10", "30", "*", "+"};
  int ret = evalRPN(input);
  cout << ret << endl;

  return 0;
}
